<?php
	require_once 'defines.php';
	require_once 'User/user.php';
	require_once 'includes/header.php';
	require_once 'DB/connect.php';
	$user = $_REQUEST["username"];
	$pass = $_REQUEST["password"];
	
	mysql_select_db(DB_NAME, $con);
	$username = mysql_query("SELECT * FROM users WHERE username='$user'");
	
	if($username != null){
		$row = mysql_fetch_array($username);
		
		if($row['password'] == md5($pass)){
			$userObj = new User($row['id'], $row['username'], $row['firstname'], $row['lastname']);
			session_start();
			echo "<h1>Login Successful! Redirecting...";
			$_SESSION['user'] = $userobj;
			echo '<meta http-equiv="REFRESH" content="2;url=http://localhost/main.php">';
		}
		else{
			echo "Login Failed! Redirecting...";
			echo'<meta http-equiv="REFRESH" content="2;url=http://localhost/Login/login.php">';
		}
	}
	require_once 'DB/disconnect.php';
	require_once 'includes/footer.php';
?>